<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<a href="${ctp}/manager/repermiss ">测试用添加权限</a>


<div class="zTreeDemoBackground left">
	<ul id="treeDemo" class="ztree"></ul>
</div>
<br/>
<button id="getTree">保存</button>
<script type="text/javascript">
	var setting = {
		data : {
			simpleData : {
				enable : true,
				pIdKey : "pid"
			},
			key: {
				url: "nourl"
			}
		},
		edit : {
			enable : true
			
			
		},
		treeNode : {
			open : true
		}
	};
	var treeObj;
	var zNodes = ${permisses};
	$(document).ready(function() {
		treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
	});
	$("#getTree").click(function(){
		var nodes = treeObj.getNodes();
		var mynode = treeObj.transformToArray(nodes);
		var needNode = [];
		$.each( mynode, function(i){
			var TPermiss = {
					"id":this.id, 
					"pid":this.pid, 
					"name":this.name,
					"url":this.url,
					"icon":this.icon
			}
			needNode[i] = TPermiss;
		});
		console.log(needNode);
		var nNode = JSON.stringify(mynode);
		$.ajax({ url: "${ctp}/permiss/savePermiss",
			type: "POST",
			data: nNode,
			contentType : "application/json",
			dataType: "json",
			success: function(data){
		    	console.log(data);
			}
		});
	});
	
	
//	ztree有自己的修改节点方法
// 	var alterbtn = $("<button data-toggle='popover' class='glyphicon glyphicon-remove  btn-xs'></button><button class='glyphicon glyphicon-refresh btn-xs'></button>");
// 	function addHoverDom(treeId, treeNode) {
// 		$("#" + treeNode.tId + "_a").after(alterbtn);
// 	}
// 	$("body").on("click", ".glyphicon-remove", function() {
// 		var now = $(this).parent("li").text();
// 		layer.msg( "[" + now + ']节点---删除成功');
// 	});
// 	$("body").on("click", ".glyphicon-refresh", function() {
// 		alert("修改成功！");
// 	});

	
</script>



